import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

class MyThreadPool{
    //阻塞队列,用来存放任务,
    private BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
    //将任务放入线程池
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
    //n 表示线程池里有几个线程
    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t = new Thread(()->{
                while (true){
                    try {
                        //从队列中取出任务
                        Runnable runnable = queue.take();
                        runnable.run();
                    } catch (InterruptedException e) {
                        //throw new RuntimeException(e);
                    }
                }
            });
            t.start();
        }
    }
}

public class Demo15 {
}
